//
//	 ______    ______    ______    
//	/\  __ \  /\  ___\  /\  ___\   
//	\ \  __<  \ \  __\_ \ \  __\_ 
//	 \ \_____\ \ \_____\ \ \_____\ 
//	  \/_____/  \/_____/  \/_____/ 
//
//	Powered by BeeFramework
//
//
//  FeedbackBoard.m
//  iHeima
//
//  Created by he chao on 6/4/14.
//  Copyright (c) 2014 leon. All rights reserved.
//

#import "FeedbackBoard.h"

#pragma mark -

@interface FeedbackBoard()
{
	//<#@private var#>
}
@end

@implementation FeedbackBoard
DEF_SIGNAL(SEND)

- (void)load
{
}

- (void)unload
{
}

#pragma mark - Signal

ON_CREATE_VIEWS( signal )
{
    self.title = @"意见反馈";
    [self showNaviBar];
    [self showBarButton:BeeUINavigationBar.LEFT image:IMAGESTRING(@"navi_back")];
    self.view.backgroundColor = [UIColor whiteColor];
    [self loadContent];
}

ON_DELETE_VIEWS( signal )
{
}

ON_LAYOUT_VIEWS( signal )
{
}

ON_WILL_APPEAR( signal )
{
    if (!btnSend) {
        btnSend = [BaseButton spawn];
        btnSend.frame = CGRectMake(260, 0, 60, 44);
        [btnSend setTitle:@"发送" forState:UIControlStateNormal];
        [btnSend setTitleColor:kBlueColor forState:UIControlStateNormal];
        [btnSend addSignal:FeedbackBoard.SEND forControlEvents:UIControlEventTouchUpInside];
    }
    [self.navigationController.navigationBar addSubview:btnSend];
}

ON_DID_APPEAR( signal )
{
}

ON_WILL_DISAPPEAR( signal )
{
    [btnSend removeFromSuperview];
}

ON_DID_DISAPPEAR( signal )
{
}

ON_SIGNAL3( BeeUINavigationBar, LEFT_TOUCHED, signal )
{
    [self.stack popBoardAnimated:YES];
}

ON_SIGNAL3( BeeUINavigationBar, RIGHT_TOUCHED, signal )
{
}

ON_SIGNAL2(FeedbackBoard, signal){
    if ([signal is:FeedbackBoard.SEND]) {
        if (textView.text.length == 0) {
            [[BeeUITipsCenter sharedInstance] presentMessageTips:@"请输入您的意见反馈"];
            return;
        }
        [self POST:[NSString stringWithFormat:@"%@/apiapp/feedback",kBaseUrl]].PARAM(@"uid",kUserInfo[@"uid"]).PARAM(@"session_id",kUserInfo[@"session_id"]).PARAM(@"content",textView.text);
    }
}

- (void)handleRequest:(BeeRequest *)request
{
    if(request.failed)
    {
        [[BeeUITipsCenter sharedInstance] dismissTips];
        NETWORK_ERROR
    }
    else if (request.succeed)
    {
        id json = [request.responseString mutableObjectFromJSONString];
        NSLog(@"%@",json);
        switch ([json[@"status"] intValue]) {
            case 1:
            {
                [[BeeUITipsCenter sharedInstance] presentMessageTips:@"反馈成功"];
                [self.stack popBoardAnimated:YES];
            }
                break;
        }
    }
}

- (void)loadContent{
    textView = [BeeUITextView spawn];
    textView.placeholder = @"请输入您的反馈内容";
    textView.frame = self.viewBound;
    textView.font = FONT(14);
    [textView becomeFirstResponder];
    [self.view addSubview:textView];
}

@end
